package hot_100;

public class 相交链表 {
    public static void main(String[] args) {

    }

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode tempA = headA;
        ListNode tempB = headB;
        int A = 0, B = 0;
        while (true) {
            if (headA == null) {
                if (A == 1)
                    break;
                headA = tempB;
                A = 1;
            }
            if (headB == null) {
                if (B == 1)
                    break;
                headB = tempA;
                B = 1;
            }
            if (headA == headB)
                return headA;
            headA = headA.next;
            headB = headB.next;
        }
        return null;
    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
            next = null;
        }
    }
}
